package leetcode.sort;

/**
 * @param
 * @author oyz
 * @version 1.1.0
 * @description: 二分查找算法
 * @date 2022-8-31 8:56
 */
public class BinarySearch {

    public static void main(String[] args) {
        int arr [] = {1,2,3,4,5};
        System.out.println(find(arr, 1));
    }

    public static int find(int arr[],int number){
        //  l：左边  r：右边  m：表示中间变量
        int l = 0;
        int r = arr.length - 1;
        int m ;
        while(l<=r){
            m = l+r >>>1;
            if(arr[m] == number){
                return m;
            }else if(arr[m] > number){
                r = r - 1;
            }else{
                l = l + 1;
            }
        }
        return -1;
    }

}
